package cc.lj.internal.mobilepay.infrastructure.repository.mysql;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.BasePageHelper;
import cc.lj.internal.mobilepay.domain.repository.ICiticLogRepository;
import cc.lj.internal.mobilepay.infrastructure.dao.ICiticLogMapper;
import cc.lj.internal.mobilepay.infrastructure.excepion.MobilepayExceptionEnum;
import cc.lj.internal.mobilepay.infrastructure.po.CiticLogPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 中信请求响应日志表　mysql仓储实现
 * @author liangxifeng
 * @date 2022-11-25
 */
@Repository("citicLogMysqlRespository")
public class CiticLogMysqlRespository implements ICiticLogRepository, BasePageHelper<CiticLogPO> {
    @Autowired
    private ICiticLogMapper mapper;
    @Override
    public List list(CiticLogPO entityPO) {
        QueryWrapper<CiticLogPO> wrapper = new QueryWrapper<>(entityPO);
        List<CiticLogPO> entitys = mapper.selectList(wrapper);
        return entitys;
    }

    @Override
    public Integer insert(CiticLogPO entityPO) {
        int rows = mapper.insert(entityPO);
        if( rows != 1) {
            throw new ServiceException(MobilepayExceptionEnum.INSERT_CITIC_LOG_FAILED);
        }
        return entityPO.getId();
    }

    @Override
    public Integer updateById(CiticLogPO entityPO) {
        int rows = mapper.updateById(entityPO);
        if( rows != 1) {
            throw new ServiceException(MobilepayExceptionEnum.UPDATE_CITIC_LOG_FAILED);
        }
        return rows;
    }

    @Override
    public CiticLogPO getById(Integer id) {
        CiticLogPO entityPO =  mapper.selectById(id);
        return entityPO;
    }

    @Override
    public List<CiticLogPO> getList(CiticLogPO po) {
        return this.list(po);
    }

    @Override
    public Integer deleteById(Integer id) {
        int res = mapper.deleteById(id);
        return res;
    }
}
